//
//  ContactDetailController.m
//  SouthChina
//
//  Created by creator_lq on 15/1/5.
//  Copyright (c) 2015年 科创. All rights reserved.
//
/*
#import "ContactDetailController.h"
#import "ContactDao.h"
#import "MessageSessionDao.h"
#import "MessageListViewController.h"



#define LABEL_HEIGHT 20
#define LABEL_WIDTH 60


@interface ContactDetailController ()<UIScrollViewDelegate,UIAlertViewDelegate>
{
    Contact * contact;
}

@property(nonatomic,retain) NSDictionary *otherInfo;

@end

@implementation ContactDetailController

@synthesize contactId,otherInfo,nickDetailLabel,phoneDetailLabel,qqDetailLabel,provincesDetailLabel,cityDetailLabel,addressDetailLabel,telDetailLabel,emailDetailLabel;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
       
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contactMessage:) name:CONTACT_CHANGE_BROADCAST object:nil];
   
    }
    return self;
}


- (void)contactMessage:(NSNotification *)notification{
    
    NSDictionary* msg = [notification object];
    NSString * pass_sessionId = [msg objectForKey:@"sessionID"];
    NSString * pass_businessId = [msg objectForKey:@"businessId"];
     NSString * thisSessId = [NSString stringWithFormat:@"%@_%@",MESSAGE_TYPE_P2P,contact.mID];
    if(([@"dropGrp" isEqualToString:pass_businessId]||[@"endFriendship" isEqualToString:pass_businessId])
            &&[thisSessId isEqualToString:pass_sessionId]){
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    contact = [ContactDao getContactByPKId:contactId];
    if (!contact) {
        contact = [ContactDao getContactById:contactId];
        if (!contact) {
            [self showAlerHUD:@"未获取到更多详细信息！"];
        }
    }
    [self addTitleBarWithBackBtn:contact.mNAME?contact.mNAME:@"" needReturn:YES];


    UIScrollView * linkmanView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    [linkmanView setBackgroundColor:[UIColor whiteColor]];

    [self.view addSubview:linkmanView];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    UIImageView * headImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 50, 50)];
    NSString *headStr = contact.mHEAD_IMG?contact.mHEAD_IMG:@"";
    NSURL *url= [NSURL URLWithString: [headStr hasPrefix:@"http"]?headStr:[NSString stringWithFormat:@"%@%@",DE.fileEngineeUrl,headStr]];
    headImage.layer.masksToBounds = YES;
    headImage.layer.cornerRadius = 8.0;
    [linkmanView addSubview:headImage];
    
    UILabel * nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30+headImage.frame.size.width,10, 180, 21)];
    nameLabel.text = contact.mNAME?contact.mNAME:@"";
    nameLabel.font = [UIFont boldSystemFontOfSize:15.0f];
    [linkmanView addSubview:nameLabel];
    
    
    UILabel * typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30+headImage.frame.size.width,35, 180, 21)];
    typeLabel.textColor = [UIColor lightGrayColor];
    typeLabel.font = [UIFont boldSystemFontOfSize:15.0f];
    typeLabel.text = @"学生";
    [linkmanView addSubview:typeLabel];
    
    //qunzu
    if ([contact.mTYPE isEqualToString:@"O"]) {
        typeLabel.text = @"群组";
        [headImage setImage:[UIImage imageNamed:@"group"]];
        return;
    }else{
        
        [headImage setImageWithURL:url placeholderImage:[UIImage imageNamed:@"empty_photo"]];

    }
    
    UILabel * functionLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,headImage.frame.size.height+10, 80, 30)];
    functionLabel.text = @"基本信息";
    functionLabel.font = [UIFont boldSystemFontOfSize:16.0f];
    [linkmanView addSubview:functionLabel];
    
    UIImageView * line = [[UIImageView alloc] initWithFrame:CGRectMake(10,functionLabel.frame.size.height+functionLabel.frame.origin.y, 300, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [linkmanView addSubview:line];
    
    UILabel * sexLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,line.frame.origin.y+10, LABEL_WIDTH, LABEL_HEIGHT)];
    sexLabel.text = @"性别：";
    sexLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:sexLabel];
    
    UILabel * sexDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,sexLabel.frame.origin.y, LABEL_WIDTH, LABEL_HEIGHT)];
    sexDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];

    sexDetailLabel.text = contact.mSEX?contact.mSEX:@"";
    [linkmanView addSubview:sexDetailLabel];
    
    UILabel * collegeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,sexLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    collegeLabel.text = @"学院：";
    collegeLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:collegeLabel];

    UILabel * collegeDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,collegeLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    collegeDetailLabel.text = contact.mDEPT?contact.mDEPT:@"";
    collegeDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:collegeDetailLabel];

    UILabel * majorLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,collegeLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    majorLabel.text = @"专业：";
    majorLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    UILabel * majorDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,majorLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    majorDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    majorDetailLabel.text = contact.mPROF_NAME?contact.mPROF_NAME:@"";
    
    UILabel * classLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,majorLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    classLabel.text = @"班级：";
    classLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    
    UILabel * classDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,classLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    classDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    classDetailLabel.text = contact.mCLASS_NAME?contact.mCLASS_NAME:@"";
    
    if ([@"T" isEqualToString:contact.mTYPE]) {
        typeLabel.text = @"教职工";
        collegeLabel.text = @"机构：";
    }else
    {
        typeLabel.text = @"学生";
        collegeLabel.text = @"学院：";
        [linkmanView addSubview:majorLabel];
        [linkmanView addSubview:majorDetailLabel];
        [linkmanView addSubview:classLabel];
        [linkmanView addSubview:classDetailLabel];

    }
    
    UILabel * detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,([@"T" isEqualToString:contact.mTYPE]?collegeLabel.frame.origin.y:classLabel.frame.origin.y)+5+LABEL_HEIGHT, 80, 30)];
    detailLabel.text = @"详细信息";
    detailLabel.font = [UIFont boldSystemFontOfSize:16.0f];
    [linkmanView addSubview:detailLabel];
    
    UIImageView * line2 = [[UIImageView alloc] initWithFrame:CGRectMake(10,detailLabel.frame.size.height+detailLabel.frame.origin.y, 300, 1)];
    line2.backgroundColor = [UIColor lightGrayColor];
    [linkmanView addSubview:line2];

    
    UILabel * nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,line2.frame.origin.y+5+line2.frame.size.height, LABEL_WIDTH, LABEL_HEIGHT)];
    nickLabel.text = @"昵称：";
    [nickLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:nickLabel];
    
    nickDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,nickLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    nickDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:nickDetailLabel];
    
    UILabel * phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,nickLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    phoneLabel.text = @"手机：";
    [phoneLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:phoneLabel];
    
    phoneDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,phoneLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    phoneDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:phoneDetailLabel];
    
    UILabel * qqLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,phoneLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    qqLabel.text = @"QQ：";
    [qqLabel setFont:[UIFont systemFontOfSize:15.0f]];
    [linkmanView addSubview:qqLabel];
    
    qqDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,qqLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    qqDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:qqDetailLabel];

    
    UILabel * provincesLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,qqLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    provincesLabel.text = @"省份：";
    [provincesLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:provincesLabel];
    
    provincesDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,provincesLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    provincesDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:provincesDetailLabel];
    
    UILabel * cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,provincesLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    cityLabel.text = @"城市：";
    [cityLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:cityLabel];
    
    cityDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,cityLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    cityDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:cityDetailLabel];
    
    UILabel * addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,cityLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    addressLabel.text = @"地址：";
    [addressLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:addressLabel];
    
    addressDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,addressLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    addressDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:addressDetailLabel];
    
    
    UILabel * telLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,addressLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    telLabel.text = @"固话：";
    [telLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:telLabel];
    
    telDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,telLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    telDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:telDetailLabel];

    
    UILabel * emailLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,telLabel.frame.origin.y+5+LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT)];
    emailLabel.text = @"邮件：";
    emailLabel.numberOfLines = 0;
    [emailLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [linkmanView addSubview:emailLabel];
    
    emailDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_WIDTH+40,emailLabel.frame.origin.y, 200, LABEL_HEIGHT)];
    emailDetailLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [linkmanView addSubview:emailDetailLabel];

    
    UIImage *img=[UIImage imageNamed:@"blue_btn_normal.png"];
    img=[img stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    UIButton * sendMessage = [[UIButton alloc] initWithFrame:CGRectMake(10,self.view.frame.size.height-80, (SCREEN_WIDTH)-20, 35)];
    [sendMessage addTarget:self action:@selector(sendMessage:) forControlEvents:UIControlEventTouchUpInside];
    [sendMessage setTitle:@"发送消息" forState:UIControlStateNormal];
    [sendMessage setBackgroundImage:img forState:UIControlStateNormal];
    [self.view addSubview:sendMessage];
    UIButton * deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(10,(self.view.frame.size.height)-40, (SCREEN_WIDTH)-20, 35)];
    [deleteButton addTarget:self action:@selector(deleteButton:) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setTitle:@"删除好友" forState:UIControlStateNormal];
    [deleteButton setBackgroundImage:img forState:UIControlStateNormal];
    [self.view addSubview:deleteButton];
    
    if ([contact.mREF_ID hasPrefix:@"friend_"]) {
        deleteButton.hidden = NO;
    }else
    {
        deleteButton.hidden = YES;
        sendMessage.frame = CGRectMake(10,(self.view.frame.size.height)-40, (SCREEN_WIDTH)-20, 35);

    }
    linkmanView.frame = CGRectMake(0, TITLE_BAR_HEGIHT+(YNEW), SCREEN_WIDTH, sendMessage.frame.origin.y-64);
    linkmanView.bounces = NO;
    [linkmanView setShowsHorizontalScrollIndicator:NO];
    [linkmanView setShowsVerticalScrollIndicator:NO];
    linkmanView.contentSize = CGSizeMake(SCREEN_WIDTH, emailDetailLabel.frame.origin.y+emailDetailLabel.frame.size.height+30);

    [self getOtherInfo];

    

    // Do any additional setup after loading the view.
}
-(void) setUserDate:(bool)isSecurtiy{
    
    if (isSecurtiy) {
        emailDetailLabel.text = @"保密";
        telDetailLabel.text =@"保密";
        addressDetailLabel.text = @"保密";
        cityDetailLabel.text =@"保密";
        provincesDetailLabel.text = @"保密";
        qqDetailLabel.text = @"保密";
        phoneDetailLabel.text = @"保密";
        nickDetailLabel.text = @"保密";
    }
    else{
        emailDetailLabel.text = [otherInfo objectForKey:@"email"]==[NSNull null]?@"":[otherInfo objectForKey:@"email"];
        telDetailLabel.text = [otherInfo objectForKey:@"fixedTel"]==[NSNull null]?@"":[otherInfo objectForKey:@"fixedTel"];
        addressDetailLabel.text = [otherInfo objectForKey:@"address"]==[NSNull null]?@"":[otherInfo objectForKey:@"address"];
        cityDetailLabel.text = [otherInfo objectForKey:@"cityName"]==[NSNull null]?@"":[otherInfo objectForKey:@"cityName"];
        provincesDetailLabel.text = [otherInfo objectForKey:@"provName"]==[NSNull null]?@"":[otherInfo objectForKey:@"provName"];
        qqDetailLabel.text = [otherInfo objectForKey:@"qq"]==[NSNull null]?@"":[otherInfo objectForKey:@"qq"];
        phoneDetailLabel.text = [otherInfo objectForKey:@"phone"]==[NSNull null]?@"":[otherInfo objectForKey:@"phone"];
        nickDetailLabel.text = [otherInfo objectForKey:@"nickName"]==[NSNull null]?@"":[otherInfo objectForKey:@"nickName"];
    }
    
}
 
-(void)getOtherInfo{
    
    NSDictionary *map = @{@"query_user_id":contact.mID};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [DE serverCall:@"queryUserInfo" params:map callback:^(BOOL success, int code, NSString *desc, NSDictionary *data,NSDictionary*param) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if(success)
        {
            otherInfo =  [data objectForKey:@"user"];
            bool isSercity = YES;
            if (![otherInfo isEqual:[NSNull null]]) {
                if ([@"3" isEqualToString: [otherInfo objectForKey:@"linkInfoState"]]) {
                    isSercity = NO;
                }
                else if ([@"1" isEqualToString: [otherInfo objectForKey:@"linkInfoState"]]) {
                    if ([contact.mREF_ID containString:@"friend"]) {
                        isSercity = NO;
                    }
                }
                else if ([@"2" isEqualToString: [otherInfo objectForKey:@"linkInfoState"]]) {
                    if ([contact.mREF_ID containString:@"usergrp"]) {
                        isSercity = NO;
                    }
                }
            }
            [self setUserDate:isSercity];

        }
        else{
            [self showAlerHUD:@"获取其他信息失败"];
        }
    }];
    
}

-(void)sendMessage:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)deleteButton:(id)sender
{
    NSDictionary *map = @{@"friend_id":contact.mID};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [DE serverCall:@"delFriend" params:map callback:^(BOOL success, int code, NSString *desc, NSDictionary *data,NSDictionary*param) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if(success&&data)
        {
            NSString *sessionId = [NSString stringWithFormat:@"%@_%@",MESSAGE_TYPE_P2P,contact.mID];
            [MessageSessionDao deleteMessageSession:sessionId];
            [self deleteLoackContacts];
        }
        else{
            [self showAlerHUD:@"删除好友失败！"];
        }
    }];

}
-(void)deleteLoackContacts
{
    
    NSString *addVersion = [DE getGlobalVar:[NSString stringWithFormat:@"%@_%@", [DE getGlobalVar:LOGIN_USER_REALID],[DE getGlobalVar:CONTACT_VERSION]]];
    NSDictionary *userInfo = @{@"AddressBookVersion":addVersion==nil?@"0":addVersion};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [DE serverCall:@"refreshAdBook" params:userInfo callback:^(BOOL success, int code, NSString *desc, NSDictionary *data, NSDictionary *params) {
        
        if(success){
            @try {
                [DE updateLocalDBContacts:[data objectForKey:@"txl"] sessionId:nil businessId:nil sendout:YES];
                UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"提示" message:@"删除好友成功！" delegate:self cancelButtonTitle:@"返回上一级" otherButtonTitles:nil, nil];
                [view show];
                kAppDelegate.needRefrsh = YES;
            }
            @catch (NSException *exception) {
                [self showAlerHUD:@"删除好友失败！"];
            }
            
        }else{
            [self showAlerHUD:@"删除好友失败！"];
            
        }
        
    }];

}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex==0) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    
}
@end

*/
//个人资料（如点我的同学，进入聊天场景，点右键弹出个人详情）
/* 
 我的同学，弹出个人详情，显示为“加为好友”按钮
 我的好友，弹出个人详情，显示为“删除好友”按钮
 */
//20150717

#import "ContactDetailController.h"
#import "FriendDetailViewController.h"
#import "ContactDao.h"
#import "MessageSessionDao.h"
#import "MessageListViewController.h"
@interface ContactDetailController ()
{
     Contact * contact;
    NSDictionary *userInfo;
}
@property (strong, nonatomic) IBOutlet UIImageView *headimage; //用户头像
@property (strong, nonatomic) IBOutlet UILabel *username;//用户名称
@property (strong, nonatomic) IBOutlet UILabel *userclass;//用户级别
@property (strong, nonatomic) IBOutlet UILabel *usersex;//用户性别
@property (strong, nonatomic) IBOutlet UILabel *userdepart;//用户部门
@property (strong, nonatomic) IBOutlet UILabel *usermail;//用户邮箱
@property (strong, nonatomic) IBOutlet UIButton *btmessage;//消息按钮
@property (strong, nonatomic) IBOutlet UIButton *btmobile;//电话按钮
@property (strong, nonatomic) IBOutlet UILabel *userphone;

@end

@implementation ContactDetailController
@synthesize contactId,TypeContact;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addTitleBarWithBackBtn:@"个人资料" needReturn:YES];
    UIView * viewBody = [[[NSBundle mainBundle] loadNibNamed:@"ContactDetailViewBody" owner:self options:nil] objectAtIndex:0];
    viewBody.frame = (CGRect){0, self.titlebar.frame.origin.y+self.titlebar.frame.size.height,SCREEN_WIDTH, SCREEN_HEIGHT-self.titlebar.frame.size.height};
    [self.view addSubview:viewBody];
    NSLog(@"&&&&&&&&&&& PK_ID :%@",contactId);
    
    //先查好友是否有，没有的话，查其他
    NSString *wheresql = [[NSString alloc]initWithFormat:@"where ID=%@ and operate='U' and ref_id='Friend'",contactId ];
    contact = [ContactDao getContactByWhereSQL:wheresql];
    if(!contact)
    {
        contact = [ContactDao getContactById:contactId];
        if (!contact) {
            wheresql = [[NSString alloc]initWithFormat:@"where PK_ID=%@ and operate='U' and ref_id='Friend'",contactId ];
            contact = [ContactDao getContactByWhereSQL:wheresql];
            if (!contact) {
                contact = [ContactDao getContactByPKId:contactId];
            }
        }
       
    }
    
    //queryUserInfo接口使用的是id ,不是pk_id;
    contactId = contact.mID;
    NSDictionary *map = @{@"query_user_id":contactId};
    [DE serverCall:@"queryUserInfo" params:map callback:^(BOOL success, int code, NSString *desc, NSDictionary *data,NSDictionary*param) {
    if(success)
    {
        userInfo =  [[NSDictionary alloc] initWithDictionary:[data objectForKey:@"user"]];
                NSString * strImg = [userInfo objectForKey:@"headImg"];
        //用户头像
        NSURL *url= [NSURL URLWithString: [strImg hasPrefix:@"http"]?strImg:[NSString stringWithFormat:@"%@%@",DE.fileEngineeUrl,strImg]];
        [_headimage setImageWithURL:url placeholderImage:[UIImage imageNamed:@"empty_photo"]];
        _headimage.layer.masksToBounds = YES;
        _headimage.layer.cornerRadius = 25;
                
        //用户名
        _username.text = [userInfo objectForKey:@"userName"];
                
        //用户性别
        _usersex.text = [[NSString alloc] initWithFormat:@" 性别： %@",[userInfo objectForKey:@"sex"]?[userInfo objectForKey:@"sex"]:@""];
                
        //用户部门和级别类型
        if ([@"T" isEqualToString:[userInfo objectForKey:@"type"]]) {
            _userclass.text = @"教职工";
            _userdepart.text = [[NSString alloc] initWithFormat:@" 机构 ：%@",[userInfo objectForKey:@"dept"]?[userInfo objectForKey:@"dept"]:@""];
            }
        else
            {
                _userclass.text = @"学生";
                _userdepart.text = [[NSString alloc] initWithFormat:@" 学院 ：%@",[userInfo objectForKey:@"dept"]?[userInfo objectForKey:@"dept"]:@""];
            }
                
            //用户邮箱
        NSLog(@"用户手机和邮箱是否可见：%@",[userInfo objectForKey:@"linkInfoState"]);
        if([[userInfo objectForKey:@"linkInfoState"] isEqualToString:@"2"]||
           [[userInfo objectForKey:@"linkInfoState"] isEqualToString:@"0"])
        {
            //不可见
            _usermail.text = [[NSString alloc] initWithFormat:@" 邮箱： %@",@"对方设置了邮箱不可见"];
            //用户手机
            _userphone.text = [[NSString alloc] initWithFormat:@" 手机： %@",@"对方设置了手机不可见"];
        }
        else
        {
            _usermail.text = [[NSString alloc] initWithFormat:@" 邮箱： %@",[userInfo objectForKey:@"email"]?[userInfo objectForKey:@"email"]:@"未设置"];
            //用户手机
            _userphone.text = [[NSString alloc] initWithFormat:@" 手机： %@",[userInfo objectForKey:@"phone"]?[userInfo objectForKey:@"phone"]:@"未设置"];
        }
        
       }
    else{
            [self showAlerHUD:@"获取用户信息失败"];
        }
  }];

    //消息按钮
    UIImageView *btImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20,20)];
    btImage.image = [UIImage imageNamed:@"message.png"];
    [_btmessage addSubview:btImage];
    
    //电话按钮
    UIImageView *mobileImage= [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20,20)];
    mobileImage.image = [UIImage imageNamed:@"telphone.png"];
    [_btmobile addSubview:mobileImage];
    
    
    //加为好友按钮
    UIImage *img=[UIImage imageNamed:@"blue_btn_normal.png"];
    img=[img stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    UIButton * btaddfriend = [[UIButton alloc] initWithFrame:CGRectMake(10,self.view.frame.size.height-150, (SCREEN_WIDTH)-20, 35)];
    [btaddfriend addTarget:self action:@selector(Clickaddfriend:) forControlEvents:UIControlEventTouchUpInside];
    [btaddfriend setTitle:@"去加好友" forState:UIControlStateNormal];
    [btaddfriend setBackgroundImage:img forState:UIControlStateNormal];
    [viewBody addSubview:btaddfriend];
    
    //删除好友按钮
    UIImage *img0=[UIImage imageNamed:@"red_btn_normal.png"];
    img0=[img0 stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    
    UIButton * btdeletefriend = [[UIButton alloc] initWithFrame:CGRectMake(10,self.view.frame.size.height-150, (SCREEN_WIDTH)-20, 35)];
    [btdeletefriend addTarget:self action:@selector(Clickdeletefriend:) forControlEvents:UIControlEventTouchUpInside];
    [btdeletefriend setTitle:@"删除好友" forState:UIControlStateNormal];
    [btdeletefriend setBackgroundImage:img0 forState:UIControlStateNormal];
    [viewBody addSubview:btdeletefriend];
    
    NSLog(@"个人详情》》》》：%@",contact.mREF_ID);
    
    //如果是我的同学，详情页面显示“加为好友”按钮
    //如果是我的好友，详情页面显示为“删除好友”按钮
    //先根据contactid查询是否有好友的，有的话显示删除好友，否则显示加为好友
    wheresql = [[NSString alloc]initWithFormat:@"where ID=%@ and operate='U' and ref_id='Friend'",contactId ];
    Contact *contactTmp = [ContactDao getContactByWhereSQL:wheresql];
    if(contactTmp)
    {
        btaddfriend.hidden = YES;
        btdeletefriend.hidden = NO;
    }
    else
    {
        btaddfriend.hidden = NO;
        btdeletefriend.hidden = YES;
    }
}

//点击加为好友按钮事件
-(void) Clickaddfriend:(id)sender
{ 
    FriendDetailViewController * frienddetail = [[FriendDetailViewController alloc] init];
    frienddetail.friendInfoDic =userInfo;
    frienddetail.friendtype = @"1";
    [kAppDelegate.iCSDrawerController.navigationController pushViewController:frienddetail animated:NO];
}

//点击删除好友按钮事件
-(void)Clickdeletefriend:(id)sender
{
    //二次确认
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您确定要解除好友关系吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.tag = 111;
    [alert show];
}


//点确定按钮事件（暂时处理一样，回到通讯录主页）
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag==111) //删除好友
    {
        if(buttonIndex==1)
            [self confirmDelFriend];
    }
    else {
         [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

-(void)confirmDelFriend
{
    NSDictionary *map = @{@"friend_id":contact.mID};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [DE serverCall:@"delFriend" params:map callback:^(BOOL success, int code, NSString *desc, NSDictionary *data,NSDictionary*param) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if(success&&data)
        {
            NSString *sessionId = [NSString stringWithFormat:@"%@_%@",MESSAGE_TYPE_P2P,contact.mID];
            [MessageSessionDao deleteMessageSession:sessionId];
            [self deleteLoackContacts];
        }
        else{
            [self showAlerHUD:@"删除好友失败！"];
        }
    }];
}

    

-(void)deleteLoackContacts
{
    
    NSString *addVersion = [DE getGlobalVar:[NSString stringWithFormat:@"%@_%@", [DE getGlobalVar:LOGIN_USER_REALID],[DE getGlobalVar:CONTACT_VERSION]]];
    NSDictionary *userInfo = @{@"AddressBookVersion":addVersion==nil?@"0":addVersion};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [DE serverCall:@"refreshAdBook" params:userInfo callback:^(BOOL success, int code, NSString *desc, NSDictionary *data, NSDictionary *params) {
        
        if(success){
            @try {
                [DE updateLocalDBContacts:[data objectForKey:@"txl"] sessionId:nil businessId:nil sendout:YES];
                UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"提示" message:@"删除好友成功！" delegate:self cancelButtonTitle:@"返回上一级" otherButtonTitles:nil, nil];
                
                [view show];
                kAppDelegate.needRefrsh = YES;
            }
            @catch (NSException *exception) {
                [self showAlerHUD:@"删除好友失败！"];
            }
            
        }else{
            [self showAlerHUD:@"删除好友失败！"];
            
        }
        
    }];
    
}

//发短信
- (IBAction)ClickMessage:(id)sender {
    //需要真机测试
    NSLog(@"发短信");
    NSString *sPhone = [userInfo objectForKey:@"phone"];
    if(sPhone.length == 0)
    {
       [self showAlerHUD:@"未设置手机号码"];
    }
    else
    {
        if([[userInfo objectForKey:@"linkInfoState"] isEqualToString:@"2"]||
           [[userInfo objectForKey:@"linkInfoState"] isEqualToString:@"0"])
        {
            //不可见
            [self showAlerHUD:@"对方设置了手机号码不可见"];
            return;
        }
        else{
            NSString *sUrl = [[NSString alloc]initWithFormat:@"sms://%@",sPhone];
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:sUrl]] ;//发短信
        }
       
    }
    
}

//打电话
- (IBAction)ClickMobile:(id)sender {
    //需要真机测试
     NSLog(@"打电话");
    NSString *sPhone = [userInfo objectForKey:@"phone"];
    if(sPhone.length == 0)
        [self showAlerHUD:@"未设置手机号码"];
    else
    {
        if([[userInfo objectForKey:@"linkInfoState"] isEqualToString:@"2"]||
           [[userInfo objectForKey:@"linkInfoState"] isEqualToString:@"0"])
        {
            //不可见
            [self showAlerHUD:@"对方设置了手机号码不可见"];
            return;
        }else{
            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",sPhone];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        }
        
    }
  
}

//重写提示效果(个性化)
-(void)showAlerHUD:(NSString*)text
{
    BDKNotifyHUD * hudex = [[BDKNotifyHUD alloc] initWithImage:[UIImage imageNamed:@""]  text:text];
    hudex.center = CGPointMake(self.view.center.x, _usermail.frame.origin.y+210);
    [self.view addSubview:hudex];
    [hudex presentWithDuration:1.5 speed:0.5f inView:self.view completion:^{
        [hudex removeFromSuperview];
    }];
}

@end
